<template>
  <div class="app-container">
    <div class="table">
      <div class="table-top">
        <p style="flex: 2">
          <span>{{form.nametitle}}</span>
        </p>
        <p style="justify-content: flex-end;">
          <span>净含量：</span>
          <el-select v-model="form.suttle" placeholder="请选择净含量">
            <el-option
              v-for="item in jkglist"
              :key="item.id"
              :label="item.jingzhong"
              :value="item.jingzhong"
            ></el-option>
          </el-select>
        </p>
      </div>
      <div class="table-center">
        <div class="table-center-l">
          <p>
            <span>执行标准：</span>
            <span>{{form.standard}}</span>
          </p>
          <!-- <form> -->
          <p>
            <span>生产日期：</span>
            <el-autocomplete
              popper-class="my-autocomplete"
              v-model="form.dateproduced"
              :fetch-suggestions="querySearch"
              placeholder="请输入生产日期"
            >
              <template slot-scope="{ item }">
                <div class="name">{{ item.value }}</div>
              </template>
            </el-autocomplete>
            <!-- <el-input v-model="form.dateproduced" placeholder="请输入生产日期"/> -->
          </p>
          <p>
            <span>生产批号：</span>
						<el-autocomplete
              popper-class="my-autocomplete"
              v-model="form.pihao"
              :fetch-suggestions="querySearch1"
              placeholder="请输入生产批号"
            >
              <template slot-scope="{ item }">
                <div class="name">{{ item.value }}</div>
              </template>
            </el-autocomplete>
            <!-- <el-input v-model="form.pihao" name="scph" id="scph" placeholder="请输入生产批号" /> -->
          </p>
          <!-- <input type="submit" style="display: none"> -->
          <!-- </form> -->
        </div>
        <div
          class="table-center-c"
          v-if="form.status != 5 && form.status != 3 && form.status != 2 && form.status != 1"
        ></div>
        <div class="table-center-c" v-if="form.status == 1">
          <p>
            <span>等级：</span>
            <span>{{form.grades}}</span>
          </p>
          <p>
            <span>规格：</span>
            <span>{{form.specifications}}</span>
          </p>
          <p>
            <span>类别：</span>
            <span>{{form.categorys}}</span>
          </p>
        </div>
        <div class="table-center-c" v-if="form.status == 2">
          <p>
            <span>ERP编码：</span>
            <span>{{form.erpcode}}</span>
          </p>
          <p>
            <span>SAP代码：</span>
            <span>{{form.sapcode}}</span>
          </p>
          <p>
            <span>包装规格：</span>
            <span>{{form.baozhuangGrades}}</span>
          </p>
        </div>
        <div class="table-center-c" v-if="form.status == 3">
          <p>
            <span>物料代码：</span>
            <span>{{form.materielcode}}</span>
          </p>
          <p>
            <span>供应商：</span>
            <span>{{form.suppliers}}</span>
          </p>
          <p>
            <span>包装规格：</span>
            <span>{{form.baozhuangGrades}}</span>
          </p>
        </div>
        <div class="table-center-c" v-if="form.status == 5">
          <p>
            <span>等级：</span>
            <span>{{form.grades}}</span>
          </p>
          <p>
            <span>包装规格：</span>
            <span>{{form.baozhuangGrades}}</span>
          </p>
        </div>
        <div class="table-center-r">
          <p>
            <span>生产许可证编号：</span>
            <span>{{form.tab}}</span>
          </p>
          <p v-if="form.status == 6 || form.status == 7">
            <span>规 格：</span>
            <el-select v-model="form.specifications" placeholder="请选择规格">
              <el-option
                v-for="item in mkglist"
                :key="item.id"
                :label="item.maozhong"
                :value="item.maozhong"
              ></el-option>
            </el-select>
            <!-- <el-input v-model="form.specifications" placeholder="规格"></el-input> -->
          </p>
          <p v-if="form.kg">
            <span>毛 重：</span>
            <el-select v-model="form.kg" placeholder="请选择毛重">
              <el-option
                v-for="item in mkglist"
                :key="item.id"
                :label="item.maozhong"
                :value="item.maozhong"
              ></el-option>
            </el-select>
          </p>
          <p v-if="form.hanliang">
            <span>含 量：</span>
            <!-- <el-input v-model="form.hanliang" placeholder="含量"></el-input> -->
            <span>{{form.hanliang}}</span>
          </p>
        </div>
      </div>
      <!-- tale底部 -->
      <div class="table-btm">
        <div>
          <p>
            <span v-if="form.tradename">商品名：</span>
            <span v-if="form.tradename">{{form.tradename}}</span>
          </p>
          <p v-if="form.piwen">
            <span v-if="form.piwen">批准文号：</span>
            <span>{{form.piwen}}</span>
          </p>
          <p style="text-align: right;">
            <span>{{form.type}}</span>
          </p>
        </div>
        <div>
          <p>
            <span>成分表：</span>
            <span>{{form.chengfenvalues}}</span>
          </p>
        </div>
        <div>
          <p>
            <span>保质期：</span>
            <span>{{form.expirations}}</span>
          </p>
        </div>
        <div>
          <p>
            <span>使用量：</span>
            <span>{{form.use}}</span>
          </p>
        </div>
        <div>
          <p>
            <span>使用方法：</span>
            <span>{{form.method}}</span>
          </p>
        </div>
        <div>
          <p>
            <span>适用范围：</span>
            <span>{{form.scope}}</span>
          </p>
        </div>
        <div v-if="form.ensurevalue">
          <p>
            <span>成分保证值：</span>
            <span>{{form.ensurevalue}}</span>
          </p>
        </div>
        <div>
          <p style="width: 90%;">
            <span>贮藏方法：</span>
            <span>{{form.condition}}</span>
          </p>
        </div>
        <div>
          <p>
            <span>注意事项：</span>
            <span>{{form.notice}}</span>
          </p>
        </div>
        <!-- <div>
					<p>
						<span>备注：</span>
						<span>乳酸钙粉</span>
					</p>
        </div>-->
        <h6>
          <div style="display: flex; align-items: center;">
            <img src="@/assets/img/qingzhen.jpg" width="100" v-if="form.status == 7" />
            <img src="@/assets/img/kosher.png" width="100" v-if="form.status == 8" />
            <svg
              width="200px"
              height="70px"
              version="1.1"
              xmlns="http://www.w3.org/2000/svg"
              style="margin: 0px;"
            >
              <polygon
                points="50,31 120,59  190,31  120,1"
                style="fill:#FFFFFF;stroke:#000000;stroke-width:2;"
              />
              <text style="fill: black;font-size: 16px;" x="95" y="35">合&nbsp;&nbsp;&nbsp;&nbsp;格</text>
            </svg>
          </div>
          <!-- <img src="@/assets/img/logo.jpg" alt=""> -->
        </h6>
      </div>
      <div class="tips">
        <p>本企业通过 ISO9001、ISO14001、ISO45001、ISO22000 管理体系认证</p>
        <p>
          <span>生产商：河南金丹乳酸科技股份有限公司</span>
          <span>地址：河南省周口市郸城县金丹大道08号</span>
        </p>
        <p>
          <span>电话：0394-3195355 3195318</span>
          <span>传真：0394-3195766</span>
          <span>网址：http://www.hnjindan.com</span>
        </p>
      </div>
      <div class="submit" @click="createEwm" :class="isClick ? 'disable' : ''">生成二维码</div>
    </div>
  </div>
</template>

<script>
import {
  addEwmMuban,
  getJingzhong,
  getMaozhong,
  addUserCreateEwm,
  addPhHistory,
  addTimeHistory,
  getPhHistory,
  getTimeHistory
} from "@/api/ewmApi";
export default {
  data() {
    return {
      form: {},
      jkglist: [], //净重数组
      mkglist: [], //毛重数组
      isClick: false,
			restaurants: [],
			pihaolist:[]
    };
  },
  mounted() {
		this.restaurants = this.loadAll();
		this.pihaolist = this.loadAll1();
    this.getMkglist();
    this.getJkglist();
    this.form = JSON.parse(localStorage.getItem('getewm'));
  },
  methods: {
    /**
     * 获取净重
     */
    getJkglist() {
      getJingzhong({}).then((res) => {
        console.log(res);
        this.jkglist = res.data;
      });
    },
    /**
     * 获取毛重
     */
    getMkglist() {
      getMaozhong({}).then((res) => {
        console.log(res);
        this.mkglist = res.data;
      });
    },
    /**
     * 获取日期历史记录
     */
    querySearch(queryString, cb) {
      var restaurants = this.restaurants;
      console.log('restaurants',restaurants)
      var results = queryString
        ? restaurants.filter(this.createFilter(queryString))
        : restaurants;
      // 调用 callback 返回建议列表的数据
      cb(results);
    },
    createFilter(queryString) {
      return (restaurant) => {
        return (
          restaurant.value.toLowerCase().indexOf(queryString.toLowerCase()) === 0
        );
      };
    },
    /**
     * 获取批号历史记录
     */
		querySearch1(queryString, cb) {
      var pihaolist = this.pihaolist;
      console.log('pihaolist',pihaolist)
      var results = queryString
        ? pihaolist.filter(this.createFilter1(queryString))
        : pihaolist;
      // 调用 callback 返回建议列表的数据
      cb(results);
    },
    createFilter1(queryString) {
      return (restaurant) => {
        // console.log('queryString',queryString)
        // console.log('restaurant',restaurant)
        return (
          restaurant.value.toLowerCase().indexOf(queryString.toLowerCase()) === 0
        );
      };
    },
    loadAll() {
      let arr = []
      getTimeHistory().then(res => {
        console.log(res)
        res.data.map(item => {
          arr.push({
            value: item
          })
        })
      })
      return arr
		},
		loadAll1() {
      let arr = []
      getPhHistory().then(res => {
        console.log(res)
        res.data.map(item => {
          arr.push({
            value: item
          })
        })
      })
      return arr
    },
    createEwm() {
      delete this.form.updateTime;
      delete this.form.insertTime;
      delete this.form.id;
      addPhHistory({pihao: this.form.pihao}).then(res => {
        console.log(res)
      })
      addTimeHistory({riqi: this.form.dateproduced}).then(res => {
        console.log(res)
      })
      console.log(this.form);
      localStorage.setItem('getewm',JSON.stringify(this.form))
      this.isClick = true;
      addUserCreateEwm(this.form).then((res) => {
        console.log(res);
        // this.$message({
        // 	message: res.message,
        // 	type: 'success'
        // })
        this.$router.push({
          name: "Lookdetail",
          params: {
            md: res.data.md,
          },
        });
      });
    },
  },
};
</script>

<style lang="scss" scoped>
p {
  padding: 0;
  margin: 0;
}
/deep/.el-input__inner{
  height: 32px;
  line-height: 32px;
}
.app-container {
  background: #fff;
}
.my-autocomplete {
  li {
    line-height: normal;
    padding: 7px;

    .name {
      text-overflow: ellipsis;
      overflow: hidden;
    }
    .addr {
      font-size: 12px;
      color: #b4b4b4;
    }

    .highlighted .addr {
      color: #ddd;
    }
  }
}
.table {
  width: 1100px;
  &-top {
    border-top: 3px solid #000000;
    padding: 10px 0 8px 0;
    display: flex;
    align-items: center;
    > p {
      // font-family: '宋体';
      flex: 1;
      display: flex;
      font-size: 29px;
      align-items: center;
      /deep/.el-input {
        width: 200px;
      }
      /deep/.el-input--medium .el-input__inner {
        width: 200px !important;
      }
    }
  }
  &-center {
    border-top: 3px solid #000000;
    display: flex;
    flex-wrap: wrap;
    justify-content: space-between;
    padding: 8px 0;
    // &-l{
    // 	flex: 1;
    // }
    // &-c{
    // 	flex: 1;
    // }
    // &-r{
    // 	flex: 1.5;
    // }
    > div {
      > p {
        font-family: "宋体";
        width: 100%;
        display: flex;
        font-size: 20px;
        // font-weight: bold;
        align-items: center;
        /deep/.el-input {
          width: 200px;
          height: 32px;
        }
        /deep/.el-input--medium .el-input__inner {
          width: 200px !important;
          height: 32px;
        }
      }
    }
  }
  &-btm {
    position: relative;
    border-top: 3px solid #000000;
    padding-top: 10px;
    height: 370px;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    > div {
      display: flex;
      width: 100%;
      flex-wrap: wrap;
      &:first-child {
        justify-content: space-between;
        > p {
          width: auto;
        }
      }
      > p {
        font-family: "宋体";
        width: 95%;
        // display: flex;
        font-size: 20px;
        // height: 40px;
        // font-weight: bold;
        // align-items: center;
        // >span{
        // 	&:last-child{
        // 		flex: 1;
        // 		overflow: hidden;
        // 	}
        // }
        /deep/.el-input {
          width: 200px;
        }
        /deep/.el-input--medium .el-input__inner {
          width: 200px !important;
        }
        /deep/.el-textarea {
          width: 200px !important;
        }
        &:nth-child(3) {
          justify-content: flex-end;
        }
      }
    }
    > h6 {
      position: absolute;
      right: 0;
      top: 50px;
      display: flex;
      flex-direction: column;
      align-items: center;
      > img {
        width: 100px;
        height: 100px;
        position: absolute;
        right: 30px;
        top: 100px;
      }
    }
  }
}
.tips {
  width: 100%;
  padding-top: 10px;
  > p {
    display: flex;
    justify-content: space-between;
    font-size: 25px;
    font-weight: bold;
    font-family: "黑体";
    line-height: 38px;
  }
}
.submit {
  width: 100px;
  height: 40px;
  background: #18a05e;
  border-radius: 5px;
  text-align: center;
  line-height: 40px;
  color: #fff;
  font-size: 16px;
  cursor: pointer;
}
</style>
